package com.aishua.aishuawallet.bean;

import java.io.Serializable;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * Created by aishua on 2018/8/30.
 */

public class ReqTransBean extends Header implements Serializable, IRequestString {


    private String Timestamp;
    private String clientver;
    private String opttype;
    private String usermobile;
    private String tokenid;
    private RawTransaction rawTransaction;

    public class RawTransaction {

        private String address;
        private String ethcount;
        private String gasprice;
        private String gaslimit;
        private String nonce;
        private String hexdata;

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getEthcount() {
            return ethcount;
        }

        public void setEthcount(String ethcount) {
            this.ethcount = ethcount;
        }

        public String getGasprice() {
            return gasprice;
        }

        public void setGasprice(String gasprice) {
            this.gasprice = gasprice;
        }

        public String getGaslimit() {
            return gaslimit;
        }

        public void setGaslimit(String gaslimit) {
            this.gaslimit = gaslimit;
        }

        public String getNonce() {
            return nonce;
        }

        public void setNonce(String nonce) {
            this.nonce = nonce;
        }

        public String getHexdata() {
            return hexdata;
        }

        public void setHexdata(String hexdata) {
            this.hexdata = hexdata;
        }

        @Override
        public String toString() {
            return "RawTransaction{" +
                    "address='" + address + '\'' +
                    ", ethcount='" + ethcount + '\'' +
                    ", gasprice='" + gasprice + '\'' +
                    ", gaslimit='" + gaslimit + '\'' +
                    ", nonce='" + nonce + '\'' +
                    ", hexdata='" + hexdata + '\'' +
                    '}';
        }
    }

    public String getTimestamp() {
        return Timestamp;
    }

    public void setTimestamp(String timestamp) {
        Timestamp = timestamp;
    }

    public String getClientver() {
        return clientver;
    }

    public void setClientver(String clientver) {
        this.clientver = clientver;
    }

    public String getOpttype() {
        return opttype;
    }

    public void setOpttype(String opttype) {
        this.opttype = opttype;
    }

    public String getUsermobile() {
        return usermobile;
    }

    public void setUsermobile(String usermobile) {
        this.usermobile = usermobile;
    }

    public String getTokenid() {
        return tokenid;
    }

    public void setTokenid(String tokenid) {
        this.tokenid = tokenid;
    }


    public RawTransaction getRawTransaction() {
        return rawTransaction;
    }

    public void setRawTransaction(RawTransaction rawTransaction) {
        this.rawTransaction = rawTransaction;
    }

    @Override
    public String toString() {
        return "ReqTransBean{" +
                "Timestamp='" + Timestamp + '\'' +
                ", clientver='" + clientver + '\'' +
                ", opttype='" + opttype + '\'' +
                ", usermobile='" + usermobile + '\'' +
                ", tokenid='" + tokenid + '\'' +
                ", rawTransaction=" + rawTransaction +
                '}';
    }

    @Override
    public String requestString() {

        String data = getVersion()+getCommand_ID()+getOrderID()+getSenderCode()+
                Timestamp+clientver+opttype+usermobile+tokenid+rawTransaction.getAddress()+rawTransaction.getEthcount()
                +rawTransaction.getGasprice()+rawTransaction.getGaslimit()+rawTransaction.getNonce()+rawTransaction.getHexdata();
        String hexlength =String.format("%08X",data.length());

        return hexlength+data;
    }
}
